package com.hotel.BL;

import java.util.Locale;
import java.util.ResourceBundle;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Query;
import com.google.appengine.api.datastore.Query.Filter;

public class AbstractBL {
		
	protected static DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
	
	HttpServletRequest req;
	HttpServletResponse resp;
	
	public AbstractBL()
	{
		
	}
	
	public AbstractBL(HttpServletRequest req, HttpServletResponse resp)
	{
		this.req = req;
		this.resp = resp;
	}
	
	public Query Search(String entityName, Filter filter)
	{
		Query q = new Query(entityName).setFilter(filter);
		return q;
	}
	
	protected String getResourceBundle(String label)
	{
		if(req == null)
			return null;
		HttpSession session=req.getSession(true);
		String Code = (String)session.getAttribute("LanguageCode");
		String SubCode = (String)session.getAttribute("LanguageSubcode");
	    Locale locale = new Locale(Code, SubCode);
		ResourceBundle resource = ResourceBundle.getBundle("resource", locale);
		return resource.getString(label);
	}
	
	protected String getUser()
	{
		if(req == null)
			return null;
		HttpSession session=req.getSession(true);
		return (String)session.getAttribute("user");
	}
	
	//move function daysBetween and addDays to Util
	//use Util.daysBetween / Util.addDays
}
